package Chapter2.Comparing.c5;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;

public class dateTest {
    public static void main(String[] args) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.set(calendar.YEAR,2018);
        calendar.set(calendar.MONTH,1);
        calendar.set(calendar.DATE,1);

        Calendar calendar1 = Calendar.getInstance();
        calendar1.set(calendar.YEAR,2018);
        calendar1.set(calendar.MONTH,0);
        calendar1.set(calendar.DATE,1);

        System.out.println(calendar.getTime());
        System.out.println(calendar1.getTime());

        System.out.println("------------------");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(sdf.format(calendar.getTime()));
        System.out.println("------------------");

        System.out.println(getDay(calendar1,calendar));
    }

    public static long getDay(Calendar beginDate,Calendar endDate) {
        long day=0;
        /*SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");*/

        day=(endDate.getTimeInMillis()-beginDate.getTimeInMillis())/(1000*60*60*24);
        return day;
    }
}
